<?
	require("required/dbconnect.php");
	require("required/share_function.php");
	require("required/email.php");
	
	if(isset($_POST['btnsubmit']))
	{
		$password=$_POST['password'];
		$email=$_POST['email'];
		
		$member_type=$_POST['member_type'];
		$name=$_POST['name'];
		$last_name=$_POST['last_name'];
		$sex=$_POST['sex'];
		$dob=$_POST['dob'];
		$fax=$_POST['fax'];
		$hpnumber=$_POST['hpnumber'];
		$address1=$_POST['address1'];
		$address2=$_POST['address2'];
		$postcode=$_POST['postcode'];
		$country=$_POST['country'];
		$city=$_POST['city'];
		$state=$_POST['state'];
	
		$_SESSION['registersubmit']=1;
		$_SESSION['email']=$email;
		$_SESSION['member_type']=$member_type;
		$_SESSION['name']=$name;
		$_SESSION['last_name']=$last_name;
		$_SESSION['sex']=$sex;
		$_SESSION['dob']=$dob;
		$_SESSION['fax']=$fax;
		$_SESSION['hpnumber']=$hpnumber;
		$_SESSION['address1']=$address1;
		$_SESSION['address2']=$address2;
		$_SESSION['postcode']=$postcode;
		$_SESSION['country']=$country;
		$_SESSION['city']=$city;
		$_SESSION['state']=$state;
	
		$regisdate=date('Y-m-d');
		
		$chkemail=mysql_num_rows(mysql_query("select * from os_member where email='$email'"));
		$cansubmit=true;
		$msg1="";
		$msg2="";
		$msg3="";
		
		require_once('required/recaptchalib.php');
		$resp = recaptcha_check_answer ($captcha_key_private,
											$_SERVER["REMOTE_ADDR"],
											$_POST["recaptcha_challenge_field"],
											$_POST["recaptcha_response_field"]);
		if (!$resp->is_valid) 
		{
			$msg1="<br><font color='#FF0000'>Sorry,invalid verification code.</font>";
			$cansubmit=false;
		
		}
		
		
		
		if($chkemail>0)
		{
			$msg3="<br><font color='#FF0000'>Sorry,$email already exsist.</font>";
			$cansubmit=false;
		}
		if($cansubmit==false)
		{
			require("required/header.php");
?>	
<table width="100%">
<td valign="top" height="400">
	<div class="dw_failed"> Invalid </div><br>
	<?= $msg1 ?>
	<?= $msg2 ?>
	<?= $msg3 ?>
	<br><br><br>
	<input type=button value="Back" onClick="window.open('os_register.php','_self')" class="button">
</td>
</table>
<?
			require("required/footer.php");
		}
	
		if($cansubmit==true)
		{ 
			require("required/function.php"); 
			$activatecode=(generatePassword()*30)+112233;	
			$insert=mysql_query("insert into os_member(password,email,
			member_type,member_type_selected,name,last_name,gender,dob,hpnumber,fax,address1,address2,postcode,city,state,country,activate_code,registerdate,status)
			values('$password','$email',
			'N','$member_type','$name','$last_name','$sex','$dob','$hpnumber','$fax','$address1','$address2','$postcode','$city','$state','$country','$activatecode','$regisdate','inactivate')")
			or die(mysql_error());
	
			$msg="<img src='images/icons/tick.jpg' align='absmiddle'><font color='green'>Thank you for register with us��you are now login as a member.<br>please login into ".$email." for activate your member account. 
			(Please check your junk mail if activation email is not in your inbox)</font>";
			
			$to=$email; //receiver email here
		
	//------------------------ get data -----------------------------------
	$getid=mysql_query("select * from os_member where email='$email' limit 1");
	$subject=$websitename_eng." member activation";
	$id=mysql_result($getid,0,'id');
	
	
	
	$_SESSION['loginname']=$name;
	$_SESSION['loginid']=$id;
	$_SESSION['email']=$email;
	$_SESSION['member_status']='inactivate';

	if($member_type=="N")
	{	
		email_normal_member_register($id,$activatecode);
	}else{
		email_vip_member_register($id,$activatecode);
	}
	
	
	
	unset($_SESSION['member_type']);
	unset($_SESSION['name']);
	unset($_SESSION['last_name']);
	unset($_SESSION['sex']);
	unset($_SESSION['dob']);
	unset($_SESSION['fax']);
	unset($_SESSION['hpnumber']);
	unset($_SESSION['address1']);
	unset($_SESSION['address2']);
	unset($_SESSION['postcode']);
	unset($_SESSION['country']);
	unset($_SESSION['city']);
	unset($_SESSION['state']);
		
	header("Location:os_register3.php?name=$name&email=$email");	
 } 
	}
?>
